import java.awt.*;

/**
 * Created by obila_000 on 2014/11/8.
 */
public class LBlock extends Gizmos{
    private float squareLength;

    private Color color = new Color(95, 210,75);

    // Keep track of the animation window that will be drawing this ball.
    private AnimationWindow win;

    /**
     * Constructor.
     * @param win Animation window that will be drawing this ball.
     */
    public LBlock(AnimationWindow win) {
        super(win);
        this.win = win;
        this.x = 0;
        this.y = 0;
        this.squareLength = 20;
        this.setType(Gizmos_type.SQURE);
    }

    /**
     * Constructor.
     * @param win Animation window that will be drawing this ball.
     */
    public LBlock(AnimationWindow win, float x, float y, float squareLength) {
        super(win);
        this.win = win;
        this.x = x;
        this.y = y;
        this.squareLength = squareLength;
        this.setType(Gizmos_type.LBLOCK);
    }

    /**
     * @modifies the Graphics object <g>.
     * @effects paints a circle on <g> reflecting the current position
     * of the ball.
     * @param g Graphics context to be used for drawing.
     */
    @Override public void paint(Graphics g) {

        // the "clip rectangle" is the area of the screen that needs to be
        // modified
        Rectangle clipRect = g.getClipBounds();

        // For this tiny program, testing whether we need to redraw is
        // kind of silly.  But when there are lots of objects all over the
        // screen this is a very important performance optimization
        if (clipRect.intersects(this.boundingBox())) {
            g.setColor(color);
            Graphics2D graphics2D = (Graphics2D)g;
            AlphaComposite ac2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.getPellucidity());
            graphics2D.setComposite(ac2);
            int topX[] = {(int)(x),(int)(x + (squareLength*2*scare)),(int)(x + (squareLength*2*scare)),(int)(x - (squareLength*scare)),
                    (int)(x - (squareLength*scare)),(int)(x)};
            int topY[] = {(int)(y),(int)(y),(int)(y - (squareLength*scare)),(int)(y - (squareLength*scare)),(int)(y + (squareLength*scare))
                    ,(int)(y + (squareLength*scare))};

            //旋转
            //action();
//            int[][] newTops = Physics.afterRotate(topX,topY,rotation,(int)x,(int)y);
//            this.setShape(new Polygon(newTops[0], newTops[1], 6));
//            g.fillPolygon(newTops[0], newTops[1], 6);

            //恢复透明度
            AlphaComposite oringe = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
            graphics2D.setComposite(oringe);
        }
    }

    /**
     * @return the smallest rectangle that completely covers the current
     * position of the ball.
     */
    @Override public Rectangle boundingBox() {

        // a Rectangle is the x,y for the upper left corner and then the
        // width and height
        return new Rectangle((int)(x - squareLength), (int)(y + squareLength), (int)(squareLength*3),
                (int)(squareLength*2));
    }

    @Override public void judgeCollispeWithBall(BouncingBall ball){
//        Point ballPos = ball.getBallCenterPos();
//        float ballRadius = ball.getRadius();
//        if(this.getShape()!=null&&this.getShape().contains(ballPos)){
//            ball.randomBump();
//            for(Gizmos gizmos:getConnectedGizmos()){
//                gizmos.startDoAction();
//            }
//        }
    }

//    @Override public boolean inGizmos(Point point){
//        if(this.getShape().contains(point)){
//            return true;
//        }
//        return false;
//    }

    @Override public void startFocusAnimation(){
        setPellucidity(0.5f);
    }

    @Override public void startLeaveAnimation(){
        setPellucidity(1.0f);
    }
}
